package com.code.user.config.token;

import com.code.user.btv.bo.AccountBO;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: Yan
 * @date: 2023/4/14
 */
public class TokenEnhancerExt implements TokenEnhancer {

    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        AccountBO principal = (AccountBO) authentication.getPrincipal();

        // 增强的内容 map
        Map<String, Object> enhancerContent = new HashMap<>();

        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(enhancerContent);
        return accessToken;
    }

}
